-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
libexpr: derivationOf primop #14956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
libexpr: derivationOf primop #14956
Conversation
|
This should reject nonsensical inputs, just like my Nixpkgs implementation would.
Overly lenient functions produce garbage inputs to other functions, which then produce garbage errors, and we can't make functions less lenient without breaking user expressions, so this really has to be done with care and a bunch of "adversarial" tests. |
0fff477 to
210b7fc
Compare
210b7fc to
08f9ac6
Compare
|
Awesome. Could you make sure the returned string has the correct context? |
|
@roberth I appreciate your patience and working through this change with me!
Done. Does this seem like the right context?
Done. Do you see any additional tests that might be beneficial?
see nix-repl> builtins.derivationOf "/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-test"
error:
… while calling the 'derivationOf' builtin
at «string»:1:1:
1| builtins.derivationOf "/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-test"
| ^
error: '/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-test' has no derivation in its context
I would opt to open an issue against the ca-derivation milestone. |
roberth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost done :)
| system = "x86_64-linux"; | ||
| }; | ||
| # Create a string with multiple context items by concatenating paths from different derivations | ||
| multipleContexts = "${drv1.outPath} ${drv2.outPath}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly more interesting test case this way, triggering the multiple contexts error instead, iiuc.
| multipleContexts = "${drv1.outPath} ${drv2.outPath}"; | |
| multipleContexts = "${drv1.outPath}${drv2.outPath}"; |
| system = "x86_64-linux"; | ||
| }; | ||
| in | ||
| builtins.derivationOf drv.outPath == drv.drvPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra test case?
I think this works, through outPath string coercion.
| builtins.derivationOf drv.outPath == drv.drvPath | |
| builtins.derivationOf drv == drv.drvPath |
It might look wrong on the face of it, because drv feels the same as drvPath, but this is actually good.
I'd much prefer to talk about "packages" despite type = "derivation"; on these things; that's just historical.
derivationOf pkg == pkg.drvPath already looks better, and we might as well name it that way in the test.
Packages more closely reflects how we reason about these things. They're all about the outputs, and the derivation (recipe) is just an implementation detail.
String context and outPath string coercion are designed to facilitate that way of thinking.
I've also yapped about this in #6507, and this builtin helps with that direction, by making drvPath largely unnecessary. (And the equality in this test shows the redundancy!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I appreciate the context. I went ahead and added these changes.
Motivation
Taken directly from the related issue - This function improves RFC 92 and multi-derivation package support, by allowing the derivation path to be accessed for any output, whose derivations may be distinct, rather than only exposing a single drvPath.
Context
Resolves #10120
Translates solution from NixOS/nixpkgs#281536 to CppNix. Thank you to @roberth for the initial implementation.
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.